import request from "@/utils/request";

/**
 * 获取商品列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getProductList(params) {
  return request({
    url: "/ht/t_product/query",
    method: "get",
    params,
  });
}

/**
 * 获取商品详情
 * @param {string} id - 商品ID
 * @returns {Promise}
 */
export function getProductDetail(params) {
  return request({
    url: `/ht/t_product/get`,
    method: "get",
    params,
  });
}

/**
 * 添加商品
 * @param {Object} data - 商品信息
 * @returns {Promise}
 */
export function addProduct(data) {
  return request({
    url: "/ht/t_product/insert",
    method: "post",
    data,
  });
}

/**
 * 更新商品
 * @param {string} id - 商品ID
 * @param {Object} data - 商品信息
 * @returns {Promise}
 */
export function updateProduct(data) {
  return request({
    url: `/ht/t_product/update`,
    method: "put",
    data,
  });
}

/**
 * 删除商品
 * @param {string} id - 商品ID
 * @returns {Promise}
 */
export function deleteProduct(productId) {
  return request({
    url: `/ht/t_product/update_status/${productId}`,
    method: "put",
  });
}

/**
 * 商品上架/下架
 * @param {string} id - 商品ID
 * @param {boolean} status - 状态
 * @returns {Promise}
 */

export function publishProduct(params) {
  return request({
    url: `/ht/t_product/publish`,
    method: "put",
    params,
  });
}

export function soldOutProduct(params) {
  return request({
    url: `/ht/t_product/sold_out`,
    method: "put",
    params,
  });
}

/**
 * 批量删除商品
 * @param {Array} ids - 商品ID数组
 * @returns {Promise}
 */
export function batchDeleteProducts(ids) {
  return request({
    url: "/shop/product/batch/delete",
    method: "post",
    data: { ids },
  });
}

/**
 * 批量修改商品状态
 * @param {Array} ids - 商品ID数组
 * @param {string} status - 状态
 * @returns {Promise}
 */
export function batchChangeProductStatus(ids, status) {
  return request({
    url: "/shop/product/batch/status",
    method: "put",
    data: { ids, status },
  });
}

/**
 * 上传商品图片
 * @param {FormData} formData - 包含图片的表单数据
 * @returns {Promise}
 */
export function uploadProductImage(formData) {
  return request({
    url: "/shop/product/upload",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 获取商品分类列表
 * @returns {Promise}
 */
export function getProductCategoryList() {
  return request({
    url: "/shop/product/category/list",
    method: "get",
  });
}

/**
 * 获取订单列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getOrderList(params) {
  return request({
    url: "/shop/order/list",
    method: "get",
    params,
  });
}

/**
 * 获取订单详情
 * @param {string} id - 订单ID
 * @returns {Promise}
 */
export function getOrderDetail(id) {
  return request({
    url: `/shop/order/${id}`,
    method: "get",
  });
}

/**
 * 更新订单状态
 * @param {string} id - 订单ID
 * @param {Object} data - 订单状态信息
 * @returns {Promise}
 */
export function updateOrderStatus(id, data) {
  return request({
    url: `/shop/order/${id}/status`,
    method: "put",
    data,
  });
}

/**
 * 获取订单物流信息
 * @param {string} id - 订单ID
 * @returns {Promise}
 */
export function getOrderLogistics(id) {
  return request({
    url: `/shop/order/${id}/logistics`,
    method: "get",
  });
}

/**
 * 取消订单
 * @param {string} id - 订单ID
 * @param {Object} data - 取消原因等信息
 * @returns {Promise}
 */
export function cancelOrder(id, data) {
  return request({
    url: `/shop/order/${id}/cancel`,
    method: "put",
    data,
  });
}

/**
 * 删除订单
 * @param {string} id - 订单ID
 * @returns {Promise}
 */
export function deleteOrder(id) {
  return request({
    url: `/shop/order/${id}`,
    method: "delete",
  });
}

/**
 * 申请退款
 * @param {string} id - 订单ID
 * @param {Object} data - 退款信息
 * @returns {Promise}
 */
export function applyRefund(id, data) {
  return request({
    url: `/shop/order/${id}/refund`,
    method: "post",
    data,
  });
}

/**
 * 处理退款
 * @param {string} id - 订单ID
 * @param {Object} data - 处理结果
 * @returns {Promise}
 */
export function processRefund(id, data) {
  return request({
    url: `/shop/order/${id}/refund/process`,
    method: "put",
    data,
  });
}

/**
 * 获取订单统计数据
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getOrderStatistics(params) {
  return request({
    url: "/shop/order/statistics",
    method: "get",
    params,
  });
}
